﻿using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Protocols;

#pragma warning disable 1591

namespace AutoProbe.ProbeWebService
{
    /// <remarks />
    [GeneratedCode("System.Web.Services", "4.0.30319.1")]
    [DebuggerStepThrough]
    [DesignerCategory("code")]
    [WebServiceBinding(Name = "ProbingSoap", Namespace = "http://MedianamikDocumentation.webservice/")]
    public class Probing : SoapHttpClientProtocol
    {
        private SendOrPostCallback ProbeOperationCompleted;

        private bool useDefaultCredentialsSetExplicitly;

        /// <remarks />
        public Probing()
        {
            Url = "http://mercure4:82/Probing.asmx";
            if (IsLocalFileSystemWebService(Url))
            {
                UseDefaultCredentials = true;
                useDefaultCredentialsSetExplicitly = false;
            }
            else
            {
                useDefaultCredentialsSetExplicitly = true;
            }
        }

        public new string Url
        {
            get { return base.Url; }
            set
            {
                if (((IsLocalFileSystemWebService(base.Url)
                      && (useDefaultCredentialsSetExplicitly == false))
                     && (IsLocalFileSystemWebService(value) == false)))
                {
                    base.UseDefaultCredentials = false;
                }
                base.Url = value;
            }
        }

        public new bool UseDefaultCredentials
        {
            get { return base.UseDefaultCredentials; }
            set
            {
                base.UseDefaultCredentials = value;
                useDefaultCredentialsSetExplicitly = true;
            }
        }

        /// <remarks />
        public event ProbeCompletedEventHandler ProbeCompleted;

        /// <remarks />
        [SoapDocumentMethod("http://MedianamikDocumentation.webservice/Probe",
            RequestNamespace = "http://MedianamikDocumentation.webservice/",
            ResponseNamespace = "http://MedianamikDocumentation.webservice/", Use = SoapBindingUse.Literal,
            ParameterStyle = SoapParameterStyle.Wrapped)]
        public void Probe(string xmlInfos)
        {
            Invoke("Probe", new object[]
                                {
                                    xmlInfos
                                });
        }

        /// <remarks />
        public void ProbeAsync(string xmlInfos)
        {
            ProbeAsync(xmlInfos, null);
        }

        /// <remarks />
        public void ProbeAsync(string xmlInfos, object userState)
        {
            if ((ProbeOperationCompleted == null))
            {
                ProbeOperationCompleted = new SendOrPostCallback(OnProbeOperationCompleted);
            }
            InvokeAsync("Probe", new object[]
                                     {
                                         xmlInfos
                                     }, ProbeOperationCompleted, userState);
        }

        private void OnProbeOperationCompleted(object arg)
        {
            if ((ProbeCompleted != null))
            {
                var invokeArgs = ((InvokeCompletedEventArgs) (arg));
                ProbeCompleted(this,
                               new AsyncCompletedEventArgs(invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }

        /// <remarks />
        public new void CancelAsync(object userState)
        {
            base.CancelAsync(userState);
        }

        private bool IsLocalFileSystemWebService(string url)
        {
            if (((url == null)
                 || (url == string.Empty)))
            {
                return false;
            }
            var wsUri = new Uri(url);
            if (((wsUri.Port >= 1024)
                 && (string.Compare(wsUri.Host, "localHost", StringComparison.OrdinalIgnoreCase) == 0)))
            {
                return true;
            }
            return false;
        }
    }

    /// <remarks />
    [GeneratedCode("System.Web.Services", "4.0.30319.1")]
    public delegate void ProbeCompletedEventHandler(object sender, AsyncCompletedEventArgs e);
}

#pragma warning restore 1591